package com.zjlanyun.erp.interior.warehouse;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.zjlanyun.erp.R;
import com.zjlanyun.erp.rfid.m10.u8.reader.model.InventoryBuffer;

import java.util.List;

/**
 * @author: shun
 * @date: 2016-12-18 13:50
 * @Desc:
 */

public class EPCAdapter extends BaseAdapter {

    private List<InventoryBuffer.InventoryTagMap> mList;
    private LayoutInflater mInflater;

    public final class ListItemView {
        public TextView strEPC;
        public TextView sort;
    }

    public EPCAdapter(Context context, List<InventoryBuffer.InventoryTagMap> mList) {
        this.mList = mList;
        this.mInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ListItemView listItemView = null;
        if (convertView == null) {
            listItemView = new ListItemView();
            convertView = mInflater.inflate(R.layout.inventory_epc_item, null);
            listItemView.strEPC = (TextView) convertView.findViewById(R.id.tv_epc);
            listItemView.sort = (TextView) convertView.findViewById(R.id.tv_sort);
            convertView.setTag(listItemView);
        } else {
            listItemView = (ListItemView) convertView.getTag();
        }
        listItemView.sort.setText(String.valueOf(position + 1) + "、");
        listItemView.strEPC.setText(mList.get(position).getStrEPC());

        return convertView;
    }
}
